package com.zsrt.springboot;

import com.netflix.client.ClientFactory;
import com.netflix.client.http.HttpRequest;
import com.netflix.client.http.HttpResponse;
import com.netflix.config.ConfigurationManager;
import com.netflix.niws.client.http.RestClient;

/**
 * 
 * @author apples
 *
 */
public class Client{
    public static void main( String[] args) throws Exception{
    	//設置服務列表
    	ConfigurationManager.getConfigInstance().setProperty("scott-client.ribbon.listOfServers", "localhost:8080,localhost:8081");
    	
    	RestClient client = (RestClient)ClientFactory.getNamedClient("scott-client");
    	
    	HttpRequest request = HttpRequest.newBuilder().uri("/student?id=1010").build();
    	
    	for(int index=1;index<=10;index++){
    		
    		HttpResponse response = client.executeWithLoadBalancer(request);
    		String json = response.getEntity(String.class);
    		System.out.println(json);
    	}
    }
}
